Managing Transactions Using WS-AppServer |
|
A transaction may involve operations (insert, update, or delete) pertaining to a single or multiple database. At times it is difficult to accommodate several such operations in a single transaction at the same time. In absence of a robust transaction management system, the transactions may give in to the load and abort mid-way.
Using WS-AppServer, you can develop business logic pertaining to your application that would handle transactions intelligently and effectively, irrespective of the load that is undertaken. WS-AppServer provides a transaction management framework that ensures smooth committing of all transactions.
The transaction management framework of WS-AppServer contains methods that effectively start, commit, and abort transactions depending upon the logic that is provided. Such flexibility in handling transactions makes processing multiple database operations in one transaction possible. If any of the operations fail, the entire transaction will be rolled back. The transaction would be committed only if all the operations succeed.
Handling Distributed Transactions
In the context of transaction management, WS-AppServer leverages the Reliable Messaging capabilities provided by Process Platform to support Distributed Transactions, where the insert, update, or delete operation is performed on two or more data sources. Distributed Transactions are helpful when applications have to update data in a distributed setup.
Distributed Transactions are managed by a Transaction Manager. However, in the case of Distributed Transactions, the Transaction Manager initiates a transaction at a higher level to keep a track of the sequential transactions that need to be completed before the final commit command is issued. If one of the sequential transactions fail, the entire transaction is rolled back.
This logic is available in the form of annotations that need to be added to the Java classes in WS-AppServer. This setup ensures that even in a distributed setup, transaction integrity is maintained and data losses are avoided. To use this feature, WS-AppServer provides annotations that you can use in the WS-AppServer classes. There are two types of annotations:
- DistributedTransaction- Used to annotate BusObject class and the related setter methods
- StartDistributedTransaction - Used for BSFJavaCall methods
EXAMPLE
Assume that you want to initiate a Distributed Transaction for any
Insert or
Delete operation that takes place on the Region class and its attributes. At the same time, you want to initiate a Distributed Transaction for the
Update operation if it is carried out only on the RegionDescription attribute of the Region class. In such case, you will use the DistributedTransaction annotation in the Extension class (Region) of the generated Java code as shown in the code below:@DistributedTransaction({OperationType.INSERT, OperationType.DELETE}) public class Region extends RegionBase { public Region() { this((BusObjectConfig)null); } public Region(BusObjectConfig config) { super(config); } @Override @DistributedTransaction({OperationType.UPDATE}) public void setRegionDescription(String value) { super.setRegionDescription(value); } }
- When Region object is part of the transaction and is being inserted or deleted, the Distributed Transaction is initiated
- When Region object is part of the transaction and is being updated and RegionDescription value has been changed, only then the Distributed Transaction comes into picture. When the update results in change of attributes other than RegionDescription the transaction will remain local.
On the other hand, to initiate Distributed Transaction for Java Call methods, you can use the following logic:@StartDistributedTransaction public void process() { …….. …….. }
When WS-AppServer Service invokes the process method, it will transform the local transaction into a distributed transaction.
Thus, you can handle Distributed Transactions in Process Platform.
Note: You need to configure the WS-AppServer Service Container to handle the Distributed Transactions. Without the required configuration, WS-AppServer cannot handle it. On the Connection Point dialog box of the WS-AppServer Service Container, you need to select the Enable Distributed Transaction Support check box to enable Distributed Transaction management. For procedural details, see topic Configuring Distributed Transaction for TCP/IP.